package es.uclm.itsue.dosd;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.graphics.drawable.shapes.RectShape;
import android.os.Bundle;
import android.widget.ImageView;

public class FrameAnimationActivity extends Activity {
	
	AnimationDrawable anim;		
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.anim_views_layout);
		
		BitmapDrawable frame1 = (BitmapDrawable)getResources()
				.getDrawable(R.drawable.dot_chart);
		BitmapDrawable frame2 = (BitmapDrawable)getResources()
				.getDrawable(R.drawable.icon);
		
		ShapeDrawable oval = new ShapeDrawable(new OvalShape());
		oval.getPaint().setColor(Color.GREEN);
		
		ShapeDrawable box = new ShapeDrawable(new RectShape());
		box.getPaint().setColor(Color.CYAN);
		
		anim = new AnimationDrawable();	
		anim.addFrame(frame1, 1000);
		anim.addFrame(frame2, 1000);
		anim.addFrame(oval,   1000);
		anim.addFrame(box,    1000);
		anim.setOneShot(false);
		
		ImageView iv = (ImageView) findViewById(R.id.img);
		iv.setBackgroundDrawable(anim);
		iv.post(new AnimStarter());
		
	}

	class AnimStarter implements Runnable {

		@Override
		public void run() {
			anim.start();
		}
	}
}
